/**  
*  Doku2Buddy - A DokuWiki to BuddyPress Wiki-Component Converter
*  Copyright (C) 2010 Skye Book
*  
*  This program is free software: you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation, either version 3 of the License, or
*  (at your option) any later version.
*  
*  This program is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*  
*  You should have received a copy of the GNU General Public License
*  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package com.sbook.d2b.gui;

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.util.ArrayList;

import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import com.sbook.d2b.formatting.DokuArticle;

/**
 * @author Skye Book
 *
 */
public class DokuViewer extends JPanel {
	private static final long serialVersionUID = 1L;
	ArrayList<Integer> articlesToRemove;
	private JList articleList;
	private JTextArea viewer;

	/**
	 * 
	 */
	public DokuViewer(final DokuArticle[] articles, int width, int height) {
		setSize(width, height);
		setLayout(new FlowLayout());
		articlesToRemove = new ArrayList<Integer>();
		
		articleList = new JList(articles);
		articleList.setPreferredSize(new Dimension(getWidth()/4, getHeight()));
		articleList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		articleList.addListSelectionListener(new ListSelectionListener() {
			@Override
			public void valueChanged(ListSelectionEvent e) {
				viewer.setText(articles[articleList.getSelectedIndex()].getMarkup());
			}
		});
		
		
		viewer = new JTextArea();
		viewer.setPreferredSize(new Dimension((getWidth()/4)*3, getHeight()));
		viewer.setText("Select an article");
		
		add(articleList);
		add(viewer);
	}
}
